package com.qy.service.impl;

import com.qy.base.core.ServiceException;
import com.qy.dao.ClueMapper;
import com.qy.dao.MemberMapper;
import com.qy.dao.PolicyMapper;
import com.qy.dao.PolicyOrderMapper;
import com.qy.model.Clue;
import com.qy.model.Member;
import com.qy.service.MemberService;
import com.qy.base.core.AbstractService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
 * Created by zaq on 2018/07/10.
 */
@Service
@Transactional
public class MemberServiceImpl extends AbstractService<Member> implements MemberService {
    @Resource
    private MemberMapper qyMemberMapper;
    @Resource
    private PolicyOrderMapper policyOrderMapper;

    @Override
    public List<Map> selectAllByName(String searchContent) {
        return qyMemberMapper.selectAllByName(searchContent);
    }

    @Override
    public List<Map> selectPolicy(String searchContent) {
        return qyMemberMapper.selectPolicy(searchContent);
    }

    @Override
    public List<Map> selectUnit(String searchContent) {
        return qyMemberMapper.selectUnit(searchContent);
    }

    @Override
    public List<Map> selectCharge(String searchContent) {
        return qyMemberMapper.selectCharge(searchContent);
    }

    @Override
    public List<Map> selectPolicys(String searchContent1, String searchContent2) {
        return qyMemberMapper.selectPolicys(searchContent1, searchContent2);
    }

    @Override
    public List<Map> selectUnits(String searchContent1, String searchContent2) {
        return qyMemberMapper.selectUnits(searchContent1, searchContent2);
    }

    @Override
    public List<Map> selectCharges(String searchContent1, String searchContent2) {
        return qyMemberMapper.selectCharges(searchContent1, searchContent2);
    }

    @Override
    public List<Map> selectAllByCity(String searchContent) {
        return qyMemberMapper.selectAllByCity(searchContent);
    }

    @Override
    public List<Map> selectMemberList(Member member) {
        return qyMemberMapper.selectMemberList(member);
    }

    @Override
    public void memberState(Member member) {
        qyMemberMapper.memberState(member);
    }

    @Override
    public List<Map> seeMember(Integer id) {
        List<Map> list = qyMemberMapper.seeMember(id);
        String amount = policyOrderMapper.selectAmount(id);
        if (amount == null) {
            amount = "0";
        }
        if (list.size() != 0) {
            list.get(0).put("profit", amount);
            return list;
        } else {
            throw new ServiceException("不存在该用户");
        }
    }

    @Override
    public List<Map> selectPolicyList(Member member) {
        return qyMemberMapper.selectPolicyList(member);
    }

    @Override
    public List<Map> selectUnitList(Member member) {
        return qyMemberMapper.selectUnitList(member);
    }

    @Override
    public List<Map> selectChargeList(Member member) {
        return qyMemberMapper.selectChargeList(member);
    }

    @Override
    public List<Map> selectRecordByUserId(Member member) {
        return qyMemberMapper.selectRecordByUserId(member);
    }

    @Override
    public List<Member> selectMemberListByOpenid(String openid) {
        return qyMemberMapper.selectMemberListByOpenid(openid);
    }
}
